package com.xfly.app.ui;

import android.os.Bundle;
import android.widget.EditText;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.view.TitleBarView;
import com.xfly.app.bean.HdBean;

import java.util.HashMap;
import java.util.Map;

public class MjActivity extends BaseMvpActivity {

    TitleBarView title_bar;
    EditText m,j;
    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();

    HdBean hdBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_mj);
    }

    @Override
    public void initViews() {
        title_bar = findViewById(R.id.title_bar);
        m = findViewById(R.id.m);
        j = findViewById(R.id.j);
    }

    @Override
    public void initEvents() {
        title_bar.setText("店铺满减");
        title_bar.setRightText("修改");
        title_bar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {
                setData();
            }
        });

        getHd();
    }


    private void getHd(){
        apiDataRepository.gethd(null, new ApiNetResponse<HdBean>() {
            @Override
            public void onSuccess(HdBean data) {
                hdBean = data;
                m.setText(data.full);
                j.setText(data.full_reduce);
            }

        });
    }

    private void setData(){
        Map<String,String> map = new HashMap<>();
        map.put("free_shipping",hdBean.free_shipping);
        map.put("postage",hdBean.postage);
        map.put("full",m.getText().toString());
        map.put("full_reduce",j.getText().toString());
        apiDataRepository.setHd(map, new ApiNetResponse<Object>(getContext()) {
            @Override
            public void onSuccess(Object data) {
                showMsg("修改成功");
                finish();
            }
        });
    }

}
